/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import java.sql.SQLException;
import javax.swing.JInternalFrame;
import DAO.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
/**
 *
 * @author Master
 */
public final class form_Main extends javax.swing.JFrame {

    /**
     * Creates new form form_Main
     */
    public form_Main() {
        initComponents();
        
        CloseForm();
        
        //form_DangNhap nv = new form_DangNhap();
        //nv.setLocation(jDesktopPane1.getLocation());
        //nv.setSize(jDesktopPane1.getSize());
        //jDesktopPane1.add(nv);
        //nv.setVisible(true);
    }
    
    DAO_DangNhap dangNhap = new DAO_DangNhap();
    public String Quyen = "";
    
    public void CloseForm(){
        for (JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnDangNhap = new javax.swing.JButton();
        btnThoat = new javax.swing.JButton();
        txtTen = new javax.swing.JTextField();
        txtMatKhau = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        menuNhanVien = new javax.swing.JMenuItem();
        menuKhachHang = new javax.swing.JMenuItem();
        menuDoanTau = new javax.swing.JMenuItem();
        menuGaTau = new javax.swing.JMenuItem();
        menuGheNgoi = new javax.swing.JMenuItem();
        menuTuyenTau = new javax.swing.JMenuItem();
        menuChuyenTau = new javax.swing.JMenuItem();
        menuPhanCong = new javax.swing.JMenuItem();
        menuChuyenGa = new javax.swing.JMenuItem();
        menuVeTau = new javax.swing.JMenuItem();
        menuDatVe = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        menu = new javax.swing.JMenu();
        menuTaiKhoan = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Tên đăng nhập:");

        jLabel2.setText("Mật khẩu:");

        btnDangNhap.setText("Đăng nhập");
        btnDangNhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDangNhapActionPerformed(evt);
            }
        });

        btnThoat.setText("Thoát");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(339, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnDangNhap)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnThoat))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(321, 321, 321))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(201, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(108, 108, 108)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDangNhap)
                    .addComponent(btnThoat))
                .addGap(78, 78, 78))
        );

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jDesktopPane1.setLayer(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jMenu1.setText("Home");

        menuNhanVien.setText("Nhân viên");
        menuNhanVien.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuNhanVienActionPerformed(evt);
            }
        });
        jMenu1.add(menuNhanVien);

        menuKhachHang.setText("Khách hàng");
        menuKhachHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuKhachHangActionPerformed(evt);
            }
        });
        jMenu1.add(menuKhachHang);

        menuDoanTau.setText("Đoàn tàu");
        menuDoanTau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuDoanTauActionPerformed(evt);
            }
        });
        jMenu1.add(menuDoanTau);

        menuGaTau.setText("Ga tàu");
        menuGaTau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuGaTauActionPerformed(evt);
            }
        });
        jMenu1.add(menuGaTau);

        menuGheNgoi.setText("Ghế Ngồi");
        menuGheNgoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuGheNgoiActionPerformed(evt);
            }
        });
        jMenu1.add(menuGheNgoi);

        menuTuyenTau.setText("Tuyến Tàu");
        menuTuyenTau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuTuyenTauActionPerformed(evt);
            }
        });
        jMenu1.add(menuTuyenTau);

        menuChuyenTau.setText("Chuyến Tàu");
        menuChuyenTau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuChuyenTauActionPerformed(evt);
            }
        });
        jMenu1.add(menuChuyenTau);

        menuPhanCong.setText("Phân công");
        menuPhanCong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPhanCongActionPerformed(evt);
            }
        });
        jMenu1.add(menuPhanCong);

        menuChuyenGa.setText("Chuyến Ga");
        menuChuyenGa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuChuyenGaActionPerformed(evt);
            }
        });
        jMenu1.add(menuChuyenGa);

        menuVeTau.setText("Vé Tàu");
        menuVeTau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuVeTauActionPerformed(evt);
            }
        });
        jMenu1.add(menuVeTau);

        menuDatVe.setText("Đặt Vé");
        menuDatVe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuDatVeActionPerformed(evt);
            }
        });
        jMenu1.add(menuDatVe);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Report");
        jMenuBar1.add(jMenu2);

        menu.setText("Account");
        menu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuActionPerformed(evt);
            }
        });

        menuTaiKhoan.setText("Tài khoản");
        menuTaiKhoan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuTaiKhoanActionPerformed(evt);
            }
        });
        menu.add(menuTaiKhoan);

        jMenuBar1.add(menu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuNhanVienActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNhanVienActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            if("Quản lý".equals(Quyen)){
                form_NhanVien nv = new form_NhanVien();
                nv.setLocation(jDesktopPane1.getLocation());
                nv.setSize(jDesktopPane1.getSize());
                jDesktopPane1.add(nv);
                nv.setVisible(true);
            }
            else{
                JOptionPane.showMessageDialog(null, "Ban khong duoc thao tac o day");
            }
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuNhanVienActionPerformed

    private void menuKhachHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuKhachHangActionPerformed
        // TODO add your handling code here:
        CloseForm();
        
        try {
            form_KhachHang kh = new form_KhachHang();
            kh.setLocation(jDesktopPane1.getLocation());
            kh.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(kh);
            kh.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuKhachHangActionPerformed

    private void menuDoanTauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDoanTauActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_DoanTau dt = new form_DoanTau();
            dt.setLocation(jDesktopPane1.getLocation());
            dt.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(dt);
            dt.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
      
    }//GEN-LAST:event_menuDoanTauActionPerformed

    private void menuGaTauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGaTauActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_GaTau gt = new form_GaTau();
            gt.setLocation(jDesktopPane1.getLocation());
            gt.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(gt);
            gt.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
        
    }//GEN-LAST:event_menuGaTauActionPerformed

    private void menuGheNgoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGheNgoiActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_GheNgoi gn = new form_GheNgoi();
            gn.setLocation(jDesktopPane1.getLocation());
            gn.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(gn);
            gn.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuGheNgoiActionPerformed

    private void menuTuyenTauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuTuyenTauActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_TuyenTau tt = new form_TuyenTau();
            tt.setLocation(jDesktopPane1.getLocation());
            tt.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(tt);
            tt.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuTuyenTauActionPerformed

    private void menuChuyenTauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuChuyenTauActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_ChuyenTau ct = new form_ChuyenTau();
            ct.setLocation(jDesktopPane1.getLocation());
            ct.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(ct);
            ct.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuChuyenTauActionPerformed

    private void menuPhanCongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPhanCongActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_PhanCong ct = new form_PhanCong();
            ct.setLocation(jDesktopPane1.getLocation());
            ct.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(ct);
            ct.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuPhanCongActionPerformed

    private void menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_menuActionPerformed

    private void menuTaiKhoanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuTaiKhoanActionPerformed
        // TODO add your handling code here:
        CloseForm();
        
        try {
            form_TaiKhoan nv = new form_TaiKhoan();
            nv.setLocation(jDesktopPane1.getLocation());
            nv.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(nv);
            nv.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuTaiKhoanActionPerformed

    private void btnDangNhapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDangNhapActionPerformed
        try {
            if(dangNhap.DangNhap(txtTen.getText(), txtMatKhau.getText())){
                JOptionPane.showMessageDialog(null, "Đăng nhập thành công");
                jPanel1.setVisible(false);
                Quyen = dangNhap.SendLevel();
            }
            else{
                JOptionPane.showMessageDialog(null, "Tên tài khoản hoặc mật khẩu không đúng");
            }
        } catch (SQLException ex) {
            Logger.getLogger(form_Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnDangNhapActionPerformed

    private void menuChuyenGaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuChuyenGaActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_ChuyenGa cg = new form_ChuyenGa();
            cg.setLocation(jDesktopPane1.getLocation());
            cg.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(cg);
            cg.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuChuyenGaActionPerformed

    private void menuVeTauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuVeTauActionPerformed
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_VeTau vt = new form_VeTau();
            vt.setLocation(jDesktopPane1.getLocation());
            vt.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(vt);
            vt.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuVeTauActionPerformed

    private void menuDatVeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDatVeActionPerformed
        for(JInternalFrame formChild : jDesktopPane1.getAllFrames()){
            formChild.dispose();
        }
        
        try {
            form_DatVe dv = new form_DatVe();
            dv.setLocation(jDesktopPane1.getLocation());
            dv.setSize(jDesktopPane1.getSize());
            jDesktopPane1.add(dv);
            dv.setVisible(true);
        } catch (SQLException e) {
            System.err.printf(e.getMessage());
        }
    }//GEN-LAST:event_menuDatVeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(form_Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(form_Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(form_Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(form_Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new form_Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDangNhap;
    private javax.swing.JButton btnThoat;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JMenu menu;
    private javax.swing.JMenuItem menuChuyenGa;
    private javax.swing.JMenuItem menuChuyenTau;
    private javax.swing.JMenuItem menuDatVe;
    private javax.swing.JMenuItem menuDoanTau;
    private javax.swing.JMenuItem menuGaTau;
    private javax.swing.JMenuItem menuGheNgoi;
    private javax.swing.JMenuItem menuKhachHang;
    private javax.swing.JMenuItem menuNhanVien;
    private javax.swing.JMenuItem menuPhanCong;
    private javax.swing.JMenuItem menuTaiKhoan;
    private javax.swing.JMenuItem menuTuyenTau;
    private javax.swing.JMenuItem menuVeTau;
    private javax.swing.JTextField txtMatKhau;
    private javax.swing.JTextField txtTen;
    // End of variables declaration//GEN-END:variables
}
